package com.jcli.jb51_net.article._95144;
import java.net.*;
import java.io.*; 
public class MyConnection2
{
  public static void main(String[] args) throws Exception
  {
    // Socket socket = new Socket("127.0.0.1", 8500);
    Socket socket = new Socket("www.ptpress.com.cn", 80);
    // 向服务端程序发送数据
    OutputStream ops = socket.getOutputStream();    
    OutputStreamWriter opsw = new OutputStreamWriter(ops);
    BufferedWriter bw = new BufferedWriter(opsw);
      
    bw.write("hello world\r\n\r\n");
    bw.flush();
      
    // 从服务端程序接收数据
    InputStream ips = socket.getInputStream();
    InputStreamReader ipsr = new InputStreamReader(ips);
    BufferedReader br = new BufferedReader(ipsr);
    String s = "";    
    while((s = br.readLine()) != null)
      System.out.println(s);    
    socket.close();
  }
}